// packageB/pages/package/pfep/standard_query/incoming_packing_standard/incoming_packing_standard.js
const mybehavior = require("../../../../../../behaviors/requests")
import Dialog from '@vant/weapp/dialog/dialog';
Page({
    /**
     * 页面的初始数据
     */
    behaviors: [mybehavior],
    data: {
        baseUrl: "https://logisticsengineering.gree.com/pfep2_api",
        page: 1,
        page_size: 5,
        query_cond: {},
        tb_key: "",
        list: [],
        show: false,
        activeNames: ['1'],
        activeNames1: [],
        show_list: [],
        previewImageClick: false,
        row_data: {},
        record_show: false,
        steps: [],
        active: 0,

    },
    // 跳转修改页面
    updateData(e) {
        wx.navigateTo({
            url: '/packageB/pages/package/pfep/standard_query/supplier_modify_standard/supplier_modify_standard',
            success(res) {
                res.eventChannel.emit('acceptDataFromOpenerPage', e.currentTarget.dataset.row_data.content)

            }
        })

    },
    // 预览照片
    previewPhoto(e) {
        let img_url = "https://logisticsengineering.gree.com/pfep2_api/photo_manage/fs_download?file_id=" + e.currentTarget.dataset.row_data
        console.log(img_url);
        let u = []
        u.push(img_url)
        wx.previewImage({
            current: img_url,
            urls: u,
        })
    },

    // 获取数据
    getDatas() {
        let url = this.data.baseUrl + "/standard_doc_store_manage/query_standard_doc_store"
        let data = {
            page: this.data.page,
            page_size: this.data.page_size,
            query_cond: this.data.query_cond,
            tb_key: this.data.tb_key,
        }
        this.post(url, data).then(res => {
            console.log("获取数据", res.data.results)
            let data_list = res.data.results
            for (let i in data_list) {
                data_list[i].start_time = this.GMTToStr(data_list[i].start_time)
                data_list[i].version_num = "v" + data_list[i].version_num
            }

            if (res.code == 20000) {

                this.setData({
                    list: data_list,
                    previewImageClick: true

                })

            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'error'
                })
            }
        }).catch(err => {
            console.log(err);
            wx.showToast({
                title: err.msg,
                icon: 'error'
            })
        })
    },
    // 显示详情
    showDetail(e) {
        console.log(e.currentTarget.dataset.row_data.content);
        this.setData({
            show: true,
            row_data: e.currentTarget.dataset.row_data.content
        })
    },
    // 详情弹出框关闭
    onClose() {
        this.setData({
            show: false,
            row_data: {}
        })
    },
    // 折叠面板
    onChange(event) {
        this.setData({
            activeNames: event.detail,
        });
    },
    // 折叠面板
    onChange1(event) {
        this.setData({
            activeNames1: event.detail,
        });
    },
    // 显示签审日志
    showRecorders(e) {
        console.log(e.currentTarget.dataset.row_data.recorders);
        let arr = e.currentTarget.dataset.row_data.recorders
        let steps1 = []
        for (let i in arr) {
            arr[i].time = this.GMTToStr(arr[i].time)
            let obj = {
                text: arr[i].action + "一审批意见:  " + arr[i].reason,
                desc: arr[i].name + "一审批于" + arr[i].time
            }
            steps1.push(obj)
        }
        this.setData({
            record_show: true,
            steps: steps1,
            active: arr.length - 1
        })
    },
    // 关闭签审日志
    onClose2() {

    },
    // 删除数据按钮
    deleteData(e) {
        console.log(e.currentTarget.dataset.row_data.key);
        let key = e.currentTarget.dataset.row_data.key
        Dialog.confirm({
            title: '确定删除？',
        })
            .then(() => {
                let url = this.data.baseUrl + "/standard_doc_manage/withdraw_standard_doc"
                let data = {
                    key: key
                }
                this.post(url, data).then(res => {
                    if (res.code == 20000) {
                        this.getDatas()
                    } else {
                        wx.showToast({
                            title: res.msg,
                            icon: 'error'
                        })
                    }
                }).catch(err => {
                    console.log(err);
                    wx.showToast({
                        title: err.msg,
                        icon: 'error'
                    })
                })

            })
            .catch(() => {
                // on cancel
            });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        if (this.data.previewImageClick == false) {
            this.getDatas()

        }

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})